import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;


public class TheDo extends Thread {

	private InputStream requestIS;
	private OutputStream responseIS;
	private httpobject httpobj;
	private String requestStr;
	private parser p1;
	private Socket s1;
	private httphandler grischanundmichaelstinken;
	
	public TheDo(Socket s11)
	{
		s1 = s11;
	}
	
	public void run()
	{
		while(true)
		{
            requestIS = null;
            responseIS = null;

            try {
			requestIS = s1.getInputStream();

            responseIS = s1.getOutputStream();
            
            int byteint = requestIS.available();
            if(byteint != 0)
            {
                byte[] bytearray = new byte[byteint];

               requestIS.read(bytearray, 0, byteint); 
              
                requestStr = new String(bytearray);
                
                p1 = new parser();
                
                httpobj = p1.parse(requestStr);
                
                grischanundmichaelstinken = new httphandler(s1);
                
                if(httpobj.function == httpobject.functionType.GET)
                {
                	grischanundmichaelstinken.execGET(httpobj.filePath, httpobj.multiHoming);
                }

            }

			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
}
